import random
import requests

# req_url = set()
# urls = [f"https://httpbin.org/get?value={random.randint(1,10)}" for i in range(10)]
#
# for url in urls:
#     if url not in req_url:
#         req_url.add(url)
#         res = requests.get(url)
#         print(res.json())
#     else:
#         print("已请求过,不需要再次请求")

import hashlib
import json

url = f"https://httpbin.org/post"

datas = [{"id":1,"value":random.randint(1,10)} for i in range(10)]
req_data = set()

for data in datas:
    # data_hash = str(data)
    # data_hash = hashlib.md5(str(data).encode("utf-8")).hexdigest()
    data_hash = hashlib.md5(json.dumps(data).encode("utf-8")).hexdigest()
    if data_hash not in req_data:
        req_data.add(data_hash)
        res = requests.post(url, data=data)
        print(res.json())
    else:
        print("已请求过, 不需要再次请求")

